using Microsoft.AspNetCore.Mvc;
using ZeroBlog.Application.Categories;
using ZeroBlog.Application.Categories.Dtos.In;
using ZeroBlog.Application.Categories.Dtos.Out;
using ZeroBlog.Application.Categories.Dtos.Query;
using ZeroSum.Models;

namespace ZeroBlog.Api.Controllers;

[ApiController]
[Route("api/[controller]/[action]")]
public class CategoryController : ControllerBase
{
    private readonly ICategoryApplicationService _applicationService;

    public CategoryController(ICategoryApplicationService applicationService)
    {
        _applicationService = applicationService;
    }

    [HttpGet]
    public async Task<PagedResponseModel<PageCategoryDto>> Page([FromQuery] PageCategoryQuery query)
    {
        return await _applicationService.Page(query);
    }

    [HttpPost]
    public async Task Add([FromBody] AddCategoryDto dto)
    {
        await _applicationService.AddAsync(dto);
    }

    [HttpPost]
    public async Task Delete([FromBody] DeleteCategoryDto dto)
    {
        await _applicationService.DeleteAsync(dto);
    }

    [HttpPost]
    public async Task Update([FromBody] UpdateCategoryDto dto)
    {
        await _applicationService.UpdateAsync(dto);
    }

    [HttpGet]
    public async Task<DetailCategoryDto> Detail([FromQuery] DetailCategoryQuery query)
    {
        return await _applicationService.Detail(query);
    }
}